//
//  ZLAlertContent.swift
//  ZLAlert
//
//  Created by 赵振磊 on 2022/11/27.
//

import Foundation

/// 内容
extension ZLAlert {
    /// 添加内容
    /// - Parameter content: 内容
    /// - Returns: ZLAlert
    @discardableResult
    public func addContent(_ content: String) -> ZLAlert {
        return self.addContent(content, ZLAlertConfig.shared.contentConfig)
    }
    /// 添加内容
    /// - Parameters:
    ///   - content: 内容
    ///   - config: 配置
    /// - Returns: ZLAlert
    @discardableResult
    public func addContent(_ content: String, _ config: ZLAlertItemConfig) -> ZLAlert {
        let lastView = self.mainView.subviews.last
        let label = UILabel.zl_label(config)
        label.text = content
        label.numberOfLines = 0
        self.mainView.addSubview(label)
        label.snp.makeConstraints { make in
            make.left.equalTo(self.mainView).offset(config.insets.left)
            make.right.equalTo(self.mainView).offset(-config.insets.right)
            if (lastView == nil) {
                make.top.equalTo(self.mainView).offset(config.insets.top)
            } else {
                make.top.equalTo(lastView!.snp.bottom).offset(config.insets.top)
            }
        }
        return self.layoutMainView(20)
    }
}
